<?php

namespace app\admin\controller;

use app\common\controller\Backend;

/**
 * 会员管理
 *
 * @icon fa fa-user
 */
class User extends Backend
{
    
    /**
     * User模型对象
     * @var \app\admin\model\User
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('User');
        $this->view->assign("sexList", $this->model->getSexList());
        $this->view->assign("isCertList", $this->model->getIsCertList());
    }
    
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    
    public function updatestatus(){
        $user_id = input('ids');
        $userInfo = \think\Db::name('user')->where(['user_id'=>$user_id])->find();
        if(!$userInfo){
            $this->error('无该用户');
        }
        if($userInfo['status'] == 1){
            $status = 0;
        }else{
            $status = 1;
        }
        $data['status'] = $status;
        \think\Db::name('user')->where(['user_id'=>$user_id])->update($data);
        $this->success();
    }
    
    public function detail(){
        $user_id = input('ids');
        $list = \think\Db::name('wallet_log')
                ->alias('a')
                ->field('a.*')
                ->join('wallet b','a.wallet_id = b.wallet_id')
                ->where(['b.user_id'=>$user_id])
                ->select();
        if($list){
            foreach($list as &$val){
                switch ($val['change_matters']) {
                    case '1':
                        $change_matters_text = '任务收入';
                        break;
                    case '2':
                        $change_matters_text = '佣金收入';
                        break;
                    case '3':
                        $change_matters_text = '平台调整';
                        break;
                    case '4':
                        $change_matters_text = '提现';
                        break;
                    case '5':
                        $change_matters_text = '佣金支出';
                        break;
                }
                $val['change_matters_text'] = $change_matters_text;
            }
            unset($val);
        }
        
        $userInfo = \think\Db::name('user')->where(['user_id'=>$user_id])->find();
        $this->view->assign('list', $list);
        $this->view->assign('userInfo', $userInfo);
        return $this->view->fetch();
    }

}
